from django.contrib import admin
from .models import (
    UserModel,
    HealthInfoCategory,
    HealthCategory,
    SubCategory,
    HealthItem,
    Hospital,
    Department,
    Doctor,
    UserQuestion,
    DoctorResponse,
    Medicine,
    DoctorHospitalMedicine,
    Video,
    Patient
)

# 自定义UserModel的显示方式
@admin.register(UserModel)
class UserModelAdmin(admin.ModelAdmin):
    list_display = ('username', 'nickname', 'phone', 'email')
    search_fields = ('username', 'nickname', 'phone')
    list_filter = ('is_staff', 'is_superuser', 'is_active')
    ordering = ('username',)
    filter_horizontal = ('groups', 'user_permissions')

# 自定义HealthInfoCategory的显示方式
@admin.register(HealthInfoCategory)
class HealthInfoCategoryAdmin(admin.ModelAdmin):
    list_display = ('title', 'description', 'link')
    search_fields = ('title', 'description')
    ordering = ('title',)

# 自定义HealthCategory的显示方式
@admin.register(HealthCategory)
class HealthCategoryAdmin(admin.ModelAdmin):
    list_display = ('name',)
    search_fields = ('name',)
    ordering = ('name',)

# 自定义SubCategory的显示方式
@admin.register(SubCategory)
class SubCategoryAdmin(admin.ModelAdmin):
    list_display = ('category', 'name')
    search_fields = ('name',)
    list_filter = ('category',)
    ordering = ('category', 'name')

# 自定义HealthItem的显示方式
@admin.register(HealthItem)
class HealthItemAdmin(admin.ModelAdmin):
    list_display = ('sub_category', 'name', 'description')
    search_fields = ('name', 'description')
    list_filter = ('sub_category',)
    ordering = ('sub_category', 'name')

# 自定义Hospital的显示方式
@admin.register(Hospital)
class HospitalAdmin(admin.ModelAdmin):
    list_display = ('name', 'address', 'is_recommend')
    search_fields = ('name', 'address')
    list_filter = ('is_recommend',)
    ordering = ('name',)

# 自定义Department的显示方式
@admin.register(Department)
class DepartmentAdmin(admin.ModelAdmin):
    list_display = ('name', 'url')
    search_fields = ('name', 'url')
    ordering = ('name',)

# 自定义Doctor的显示方式
@admin.register(Doctor)
class DoctorAdmin(admin.ModelAdmin):
    list_display = ('name', 'title', 'hospital', 'score', 'price', 'is_recommend')
    search_fields = ('name', 'title')
    list_filter = ('hospital', 'is_recommend')
    ordering = ('name',)

# 自定义UserQuestion的显示方式
@admin.register(UserQuestion)
class UserQuestionAdmin(admin.ModelAdmin):
    list_display = ( 'doctor', 'title', 'created_at')
    search_fields = ('title', 'content')
    list_filter = ('doctor',)
    ordering = ('-created_at',)

# 自定义DoctorResponse的显示方式
@admin.register(DoctorResponse)
class DoctorResponseAdmin(admin.ModelAdmin):
    list_display = ('question', 'doctor', 'created_at')
    search_fields = ('content',)
    list_filter = ('doctor',)
    ordering = ('-created_at',)

# 自定义Medicine的显示方式
@admin.register(Medicine)
class MedicineAdmin(admin.ModelAdmin):
    list_display = ('name', 'generic_name', 'price', 'is_recommend')
    search_fields = ('name', 'generic_name')
    list_filter = ('is_recommend',)
    ordering = ('name',)

# 自定义DoctorHospitalMedicine的显示方式
@admin.register(DoctorHospitalMedicine)
class DoctorHospitalMedicineAdmin(admin.ModelAdmin):
    list_display = ('recommend', 'doctor', 'hospital', 'medicine')
    search_fields = ('recommend', 'doctor', 'hospital', 'medicine')
    ordering = ('recommend',)

# 自定义Video的显示方式
@admin.register(Video)
class VideoAdmin(admin.ModelAdmin):
    list_display = ('video_file', 'uploaded_at')
    ordering = ('-uploaded_at',)

# 自定义Patient的显示方式
@admin.register(Patient)
class PatientAdmin(admin.ModelAdmin):
    list_display = ('patientName', 'gender', 'birthDate', 'weight', 'allergyHistory', 'pastMedicalHistory', 'liverFunction', 'kidneyFunction', 'pregnancyStatus', 'user')
    search_fields = ('patientName', 'gender', 'allergyHistory', 'pastMedicalHistory')
    list_filter = ('gender', 'pregnancyStatus')
    ordering = ('patientName',)
